<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
</head>
<body>
    <div class="easyui-tabs" style="width:100%;height:100%">
        <div title="查询学生成绩" style="padding:3px">
            <table id="dg_queryscore" style="height:100%">

            </table>
            <div id="queryscore_toolbar">
                <form id="fm_export_studentScore" action="exportStudentScore" method="post">
                    <input id="ex_studentName" name="studentName" class="easyui-textbox" style="width:110px" data-options="prompt:'输入学生姓名'">
                    <input id="gradeName" type="text" name="gradeName" hidden>
                <div class="param-div">
                    <select id="ex_gradeDatatableName" class="form-control-sm" name="gradeDatatableName">
                        <option value="" selected>请选择年级...</option>
                        <option th:each="gra:${session.grades}" th:value="${gra.gradeDatatableName}" th:text="${gra.gradeName}"></option>
                    </select>
                </div>
                <div class="param-div">
                    <select id="ex_teamName" class="form-control-sm" name="teamName">
                        <option value="">请选择班级...</option>
                        <option th:each="team:${session.teamsList}" th:value="${team.teamName}" th:text="${team.teamName}"></option>
                    </select>
                </div>
                <div class="param-div">
                    <select id="ex_semesterName" name="semesterName" class="form-control-sm">
                        <option value="">请选择学期...</option>
                        <option th:each="semes:${session.semesters}" th:value="${semes.semesterName}" th:text="${semes.semesterName}"></option>
                    </select>
                </div>
                <div class="param-div">
                    <select id="ex_examName" name="examName" class="form-control-sm">
                        <option value="">请选择考试...</option>
                        <option th:each="exa:${session.exams}" th:value="${exa.examName}" th:text="${exa.examName}"></option>
                    </select>
                </div>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" id="queryDetailScoreBtn" onclick="doQueryStudentDetailScore()">查询</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="doAddStudentScore()" th:if="${session.onlineUserPower<3}">增加</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="doEditStudentScore()" th:if="${session.onlineUserPower<3}">编辑</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="doDeleteStudentScore()" th:if="${session.onlineUserPower<2}">删除</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" plain="true" id="exportDetailScoreBtn" onclick="doExportStudentDetailScore()">导出到Excel</a>
                </form>
            </div>
            <div id="dg_add_edit_score" class="easyui-dialog" style="width:800px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg_buttons_score'">
                <form id="fm_add_edit_score" method="post" novalidate style="margin:0;padding:20px 50px">
                    <h4 style="text-align: center;">学生成绩信息</h4>
                    <input type="text" name="scoreId" hidden="hidden">
                    <table id="addTable" width="100%">
                        <tr>
                            <td>学生身份证号:</td><td><input name="studentIdCard"  class="easyui-textbox"style="width: 230px; height: 30px;"  type="text"  data-options="required:true,missingMessage:'请输入学生身份证号'"/></td>
                            <td>学生姓名:</td><td><input name="studentName"  class="easyui-textbox" style="width: 230px; height: 30px;" type="text"  data-options="required:true,missingMessage:'请输入学生姓名'" /></td>
                        </tr>
                        <tr>
                            <td>年级名称:</td>
                            <td>
                                <select name="gradeName" id="addStudentScoreGradeName" class="easyui-combobox" style="width: 230px;height: 30px;" data-options="editable:false,required:true,missingMessage:'请选择年级'" >
                                    <option th:each="grade : ${session.grades}"  th:value="${grade.gradeName}" th:text="${grade.gradeName}"></option>
                                </select>
                            </td>
                            <td>班级:</td>
                            <td>
                                <select name="teamName" class="easyui-combobox" style="width: 230px;height: 30px;" data-options="editable:false,required:true,missingMessage:'请选择班级'">
                                    <option th:each="team : ${session.teamsList}"  th:value="${team.teamName}" th:text="${team.teamName}"></option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>学期名称:</td>
                            <td>
                                <select id="semesterName" name="semesterName"  class="easyui-combobox" style="width: 230px;height: 30px;" data-options="editable:false,required:true,missingMessage:'请选择学期'" >
                                    <option th:each="semester : ${session.semesters}"  th:value="${semester.semesterName}" th:text="${semester.semesterName}"></option>
                                </select>
                            </td>
                            <td>考试名称:</td>
                            <td>
                                <select name="examName" id="add_ExamName" class="easyui-combobox" style="width: 230px;height: 30px;" data-options="editable:false,required:true,missingMessage:'请选择考试名称'">
                                    <option th:each="exam : ${session.exams}"  th:value="${exam.examName}" th:text="${exam.examName}"></option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>语文:</td><td><input id="chinese" name="chinese" style="width: 230px; height: 30px;" class="easyui-textbox" type="text" data-options="missingMessage:'请填写性别'"  /></td>
                            <td>数学:</td><td><input id="maths" name="maths"  class="easyui-textbox" style="width: 230px; height: 30px;" type="text"  data-options=" missingMessage:'请填写民族'"  /></td>
                        </tr>
                        <tr>
                            <td>英语:</td><td><input id="english" name="english" class="easyui-textbox" style="width: 230px; height: 30px;" type="text"   /></td>
                            <td>物理:</td><td><input id="physics" name="physics"  class="easyui-textbox" style="width: 230px; height: 30px;" type="text"   /></td>
                        </tr>
                        <tr>
                            <td>历史:</td><td><input id="history" name="history"  class="easyui-textbox" style="width: 230px; height: 30px;" type="text"   /></td>
                            <td>化学:</td><td><input id="chemistry" name="chemistry"  style="width: 230px; height: 30px;" class="easyui-textbox" type="text"   /></td>
                        </tr>
                        <tr >
                            <td>生物:</td><td><input id="biology" name="biology" style="width: 230px; height: 30px;" class="easyui-textbox" type="text"  /></td>
                            <td>政治:</td><td><input id="politics" name="politics"  class="easyui-textbox" style="width: 230px; height: 30px;" type="text"   /></td>
                        </tr>
                        <tr>
                            <td>地理:</td><td><input id="geography" name="geography"  class="easyui-textbox" style="width: 230px; height: 30px;" type="text"  /></td>
                            <td>体育:</td><td><input id="sports" name="sports" style="width: 230px; height: 30px;" class="easyui-textbox" type="text"  /></td>
                        </tr>
                        <tr>
                            <td>总分:</td><td><input name="total" id="total" class="easyui-textbox" style="width: 230px; height: 30px;" type="text" data-options="prompt:'不用填，系统会自动计算'"  /></td>
                            <td>分类:</td>
                            <td>
                                <select name="categoryName" id="categoryName" style="width: 230px; height: 30px;" class="easyui-combobox" data-options="required:true,missingMessage:'请选择类别'">
                                    <option value="未分科">未分科</option>
                                    <option value="历史类">历史类</option>
                                    <option value="物理类">物理类</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>应届(往届):</td>
                            <td>
                                <select name="origin" style="width: 230px; height: 30px;" class="easyui-combobox" data-options="required:true,missingMessage:'请选择应届往届'">
                                    <option value="应届">应届</option>
                                    <option value="往届">往届</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
            <div id="dlg_buttons_score">
                <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveStudentScore()" style="width:90px">保存</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dg_add_edit_score').dialog('close')" style="width:90px">取消</a>
            </div>

        </div>
        <div title="查询教师任课成绩" style="padding:3px">
            <table id="dg_queryTeacherScore" style="height:100%">

            </table>
            <div id="queryTeacherScore_toolbar">
                <form  id="fm_adminExportTeachScore" method="post" action="adminExportTeachScore">
                    <input id="teachGradeName" name="gradeName" type="text" hidden>
                <input id="teacherTeacherName" name="teacherName" class="easyui-textbox" style="width:110px" data-options="prompt:'输入教师姓名'">
                <div class="param-div">
                    <select id="teacherGradeDatatableName"name="gradeDatatableName" class="form-control-sm">
                        <option value="">请选择年级...</option>
                        <option th:each="gra:${session.grades}" th:value="${gra.gradeDatatableName}" th:text="${gra.gradeName}"></option>
                    </select>
                </div>
                <div class="param-div">
                    <select id="teacherTeamName" name="teamName" class="form-control-sm">
                        <option value="">请选择班级...</option>
                        <option th:each="team:${session.teamsList}" th:value="${team.teamName}" th:text="${team.teamName}"></option>
                    </select>
                </div>
                <div class="param-div">
                    <select id="teacherSemesterName" name="semesterName" class="form-control-sm">
                        <option value="">请选择学期...</option>
                        <option th:each="semes:${session.semesters}" th:value="${semes.semesterName}" th:text="${semes.semesterName}"></option>
                    </select>
                </div>
                <div class="param-div" style="width: 280px;">
                    <select id="teacherExamName" name="examName" class="form-control-sm" style="width: 280px;">
                        <option value="">请选择考试...</option>
                        <option th:each="exa:${session.exams}" th:value="${exa.examName}" th:text="${exa.examName}"></option>
                    </select>
                </div>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doQueryTeachScore()">查询</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-export" plain="true" onclick="doAdminExportTeachScore()">导出</a>
<!--                <div class="param-button"><a href="javascript:void(0)" class="btn btn-outline-primary btn-sm btn-block"  onclick="doW()">刷新</a></div>-->
<!--                <div class="param-button"><a href="javascript:void(0)" class="btn btn-outline-primary btn-sm btn-block" onclick="doDelete()">删除</a> </div>-->
                </form>
            </div>
        </div>
    </div>

<script type="text/javascript" th:inline="none">
    $(function () {
        //分页参数
        let pageParam = {
            pageSize: 30,							//每页显示的记录条数，默认为10
            pageList: [10, 20, 30, 50, 100],	//可以设置每页记录条数的列表
            beforePageText: '第',				//页数文本框前显示的汉字
            afterPageText: '页    共 {pages} 页',
            displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        }
        //查询学生成绩
        $("#dg_queryscore").datagrid({
            url: "queryStudentDetailScore?t=" + new Date().getTime(),
            toolbar: "#queryscore_toolbar",
            pagination: true,
            pageSize: 30,
            rownumbers: true,
            fitColumns: false,
            singleSelect: false, // 单行
            fit: true,
            columns: [[
                {field: 'chk', checkbox: true, width: 50},
                {field: 'scoreId', title: '编号', align:'center', hidden:true,width: 50},
                {field: 'studentIdCard', title: '学生身份证号', align:'center', width: 180},
                {field: 'studentName', title: '学生姓名', align:'center',width: 80},
                {field: 'gradeName', title: '年级名称', align:'center',width: 100},
                {field: 'teamName', title: '班级', align:'center',width: 100},
                {field: 'semesterName', title: '学期',align:'center', width: 100},
                {field: 'examName', title: '考试名称', align:'center',width: 120},
                {field: 'chinese', title: '语文', align:'center',width: 70},
                {field: 'maths', title: '数学', align:'center',width: 70},
                {field: 'english', title: '英语', align:'center',width: 70},
                {field: 'physics', title: '物理', align:'center',width: 70},
                {field: 'history', title: '历史', align:'center',width: 70},
                {field: 'chemistry', title: '化学', align:'center',width: 70},
                {field: 'biology', title: '生物', align:'center',width: 70},
                {field: 'politics', title: '政治', align:'center',width: 70},
                {field: 'geography', title: '地理', align:'center',width: 70},
                {field: 'sports', title: '体育', align:'center',width: 70},
                {field: 'total', title: '总分', align:'center',width: 70},
                {field: 'categoryName', title: '分类',align:'center', width: 100},
                {field: 'origin', title: '应届（往届）',align:'center', width: 100}
            ]]
        });
        let queryScorePage= $("#dg_queryscore").datagrid("getPager");
        $(queryScorePage).pagination(pageParam);
        //查询教师成绩
        $("#dg_queryTeacherScore").datagrid({
            url: "queryTeachScore?t=" + new Date().getTime(),
            toolbar: "#queryTeacherScore_toolbar",
            pagination: true,
            pageSize: 30,
            rowNumbers: true,
            fitColumns: true,
            singleSelect: true, // 单行
            fit: true,
            loadFilter:partPurchasePagerFilter,
            columns: [[
                {field: 'chk', checkbox: true, width: 50},
                {field: 'gradeName', title: '年级名称', align:'center',width: 100},
                {field: 'teamName', title: '班级', align:'center',width: 100},
                {field: 'semesterName', title: '学期',align:'center', width: 100},
                {field: 'examName', title: '考试名称', align:'center',width: 100},
                {field: 'categoryName', title: '分类',align:'center', width: 100},
                {field: 'studentIdCard', title: '学生身份证号', align:'center', width: 150},
                {field: 'studentName', title: '学生姓名', align:'center',width: 80},
                {field: 'subject', title: '任教学科成绩', align:'center',width: 100},
                {field: 'subjectName', title: '任教学科名称', align:'center',width: 100}
            ]],
            onLoadSuccess : function () {
                let panel = $(this).datagrid("getPanel");
                $(".datagrid-header-rownumber,.datagrid-cell-rownumber", panel).width(60);  //序列编号的宽带
            }
        });
        let queryTeacherScorePage= $("#dg_queryTeacherScore").datagrid("getPager");
        $(queryTeacherScorePage).pagination(pageParam);

    });
    //通用分页
    function partPurchasePagerFilter(data) {
        //alert(data);
        if (typeof data.length == 'number' && typeof data.splice == 'function') {
            data = {
                total : data.length,
                rows : data
            }
        }
        let dg = $(this);
        let opts = dg.datagrid('options');
        let pager = dg.datagrid('getPager');
        pager.pagination({
            onSelectPage : function(pageNum, pageSize) {
                opts.pageNumber = pageNum;
                opts.pageSize = pageSize;
                pager.pagination('refresh', {
                    pageNumber : pageNum,
                    pageSize : pageSize
                });
                dg.datagrid('loadData', data);
            }
        });
        if (!data.originalRows) {
            data.originalRows = (data.rows);
        }
        let start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
        let end = start + parseInt(opts.pageSize);
        data.rows = (data.originalRows.slice(start, end));
        return data;
    }
    //查询学生成绩
    function doQueryStudentDetailScore() {
        let gradeName= $("#ex_gradeDatatableName").find("option:selected").text();
        let gradeDatatableName= $("#ex_gradeDatatableName").val();
        if(  gradeDatatableName==""    ){
            hsycms.alert('alert', "请选择要查询的 年级!", function () {
                hsycms.close('alert');
            });
            return false;
        }
        $("#dg_queryscore").datagrid("load", {
            "gradeName": gradeName,
            "gradeDatatableName": gradeDatatableName,
            "teamName": $("#ex_teamName").val(),
            "semesterName": $("#ex_semesterName").val(),
            "examName": $("#ex_examName").val(),
            "studentName": $("#ex_studentName").val()
        });
    }
    //编辑学生成绩
    function doEditStudentScore() {
        let row = $("#dg_queryscore").datagrid('getSelections');
        if (row.length != 1) {
            hsycms.alert('alert', "请选择一行数据！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        $('#dg_add_edit_score').dialog('open').dialog('center').dialog('setTitle', '修改学生成绩');
        $('#fm_add_edit_score').form('load', row[0]);

        url = 'editStudentScore';
    }
    //删除 考试信息
    function doDeleteStudentScore() {
        let selectRows = $("#dg_queryscore").datagrid("getSelections");
        let selectLength = selectRows.length;
        if(selectLength == 0){
            $.messager.alert("消息提醒", "请选择数据进行删除!", "warning");
        } else{
            let idArray = [];
            $(selectRows).each(function(i, row){    //把要删除的id和年级传到后台
                idArray[i] = row.scoreId+"-" + row.gradeName;
            });

            $.messager.confirm("消息提醒", "确定删除该信息？", function(r){
                if(r){
                    $.ajax({
                        type: "post",
                        url: "deleteStudentScore",
                        data: {ids: idArray},
                        dataType:'json',
                        success: function(ret){
                            if(ret.type == "success"){
                                $.messager.alert("消息提醒","删除成功!","info");
                                //刷新表格
                                $("#dg_queryscore").datagrid("reload");
                                $("#dg_queryscore").datagrid("uncheckAll");
                            } else{
                                $.messager.alert("消息提醒",data.msg,"warning");
                            }
                        }
                    });
                }
            });
        }
    }
    //新增学生成绩
    function doAddStudentScore() {
        $('#dg_add_edit_score').dialog('open').dialog('center').dialog('setTitle', '新增学生成绩');
        $('#fm_add_edit_score').form('clear');
        $("#chinese").textbox('setValue',"0");
        $("#maths").textbox('setValue',"0");
        $("#english").textbox('setValue',"0");
        $("#physics").textbox('setValue',"0");
        $("#history").textbox('setValue',"0");
        $("#chemistry").textbox('setValue',"0");
        $("#biology").textbox('setValue',"0");
        $("#politics").textbox('setValue',"0");
        $("#geography").textbox('setValue',"0");
        $("#sports").textbox('setValue',"0");
        $("#total").textbox('setValue',"0");

        url = 'newAddStudentScore';
    }
    //保存学生成绩
    function saveStudentScore() {
        //窗体校验
        if (!$("#fm_add_edit_score").form('validate')) {
            return;
        }
        let regPos = /^\d+(\.\d+)?$/;   //非负浮点数
        let chinese = $("#chinese").val();
        if(!regPos.test(chinese)){
            hsycms.alert('alert', "输入的语文得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let maths = $("#maths").val();
        if(!regPos.test(maths)){
            hsycms.alert('alert', "输入的数学得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let english = $("#english").val();
        if(!regPos.test(english)){
            hsycms.alert('alert', "输入的英语得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let physics = $("#physics").val();
        if(!regPos.test(physics)){
            hsycms.alert('alert', "输入的物理得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let history = $("#history").val();
        if(!regPos.test(history)){
            hsycms.alert('alert', "输入的历史得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let chemistry = $("#chemistry").val();
        if(!regPos.test(chemistry)){
            hsycms.alert('alert', "输入的化学得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let biology = $("#biology").val();
        if(!regPos.test(biology)){
            hsycms.alert('alert', "输入的生物得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let politics = $("#politics").val();
        if(!regPos.test(politics)){
            hsycms.alert('alert', "输入的政治得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let geography = $("#geography").val();
        if(!regPos.test(geography)){
            hsycms.alert('alert', "输入的地理得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let total = $("#total").val();
        if(!regPos.test(total)){
            hsycms.alert('alert', "输入的总分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let sports = $("#sports").val();
        if(!regPos.test(sports)){
            hsycms.alert('alert', "输入的体育得分不是数字！", function () {
                hsycms.close('alert');
            });
            return false;
        }

        //校验身份证号
        // let studentIdCard = $("#studentIdCard").val();
        // if (!IdCardValidate(studentIdCard)) {
        //     return;
        // }

        let data = $("#fm_add_edit_score").serialize();
        $.ajax({
            type: "post",
            url: url,
            data: data,
            dataType: 'json',
            success: function (res) {
                if (res.type == "success") {
                    $.messager.alert("消息提醒", res.msg, "info");
                    $('#dg_add_edit_score').dialog('close');
                    $("#dg_queryscore").datagrid("reload");
                } else {
                    $.messager.alert("消息提醒", res.msg, "warning");
                }
            }
        });
    }

    //查询教师成绩
    function doQueryTeachScore() {
        if($("#teacherTeacherName").val().trim()==""){
            hsycms.alert('alert', "请输入要查询的教师姓名!", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let teamName= $("#teacherTeamName").val();
        let gradeName= $("#teacherGradeDatatableName").find("option:selected").text();
        let gradeDatatableName= $("#teacherGradeDatatableName").val();

        if(teamName.length==3&&gradeName.length>6){
            hsycms.alert('alert', "请选择年级!", function () {
                hsycms.close('alert');
            });
            return false;
        }
        if(gradeName.length>6){
            gradeName="";
        }
        let semesterName= $("#teacherSemesterName").val();
        let examName= $("#teacherExamName").val();
        let teacherName= $("#teacherTeacherName").val();
        $("#dg_queryTeacherScore").datagrid("load", {
            "gradeName":gradeName ,
            "gradeDatatableName": gradeDatatableName,
            "teamName":teamName ,
            "semesterName": semesterName,
            "examName": examName,
            "teacherName": teacherName
        });
    }
    //管理员导出教师任课成绩
    function doAdminExportTeachScore(){
        if($("#teacherTeacherName").val().trim()==""){
            hsycms.alert('alert', "请输入教师姓名!", function () {
                hsycms.close('alert');
            });
            return false;
        }

        let teamName= $("#teacherTeamName").val();
        let gradeName= $("#teacherGradeDatatableName").find("option:selected").text();
        if(teamName.length==3&&gradeName.length>6){
            hsycms.alert('alert', "请选择年级!", function () {
                hsycms.close('alert');
            });
            return false;
        }
        if(gradeName.length>6){
            gradeName="";
        }
        $("#teachGradeName").val(gradeName);
        $("#fm_adminExportTeachScore").submit();
    }
    //导出查询学生成绩
    function doExportStudentDetailScore(){
        let gradeDatatableName= $("#ex_gradeDatatableName").val();
        if(gradeDatatableName==" "){
            hsycms.alert('alert', "请选择要导出的年级!", function () {
                hsycms.close('alert');
            });
            return false;
        }
        let gradeName= $("#ex_gradeDatatableName").find("option:selected").text();
        $("#gradeName").val(gradeName);
        $("#fm_export_studentScore").submit();
    }
</script>

</body>
</html>